package org.aplikator.client.shared.descriptor;

import java.io.Serializable;

@SuppressWarnings("serial")
public abstract class ClientDescriptorBase implements Serializable {

    protected static final char PATH_DELIMITER = '.';


    /**
     * programmer - assigned string identifier (equal to the id of the corresponding server side descriptor item)
     */
    private String id;

    /**
     * localized name obtained from property resource bundle
     */
    private String localizedName;

    public ClientDescriptorBase(){}

    public ClientDescriptorBase(String id, String localizedName){
        if (id == null){
            throw new IllegalArgumentException("Null client descriptor ID");
        }
        this.id=id;
        this.localizedName=localizedName;
    }


    public String getId() {
        return id;
    }


    public String getLocalizedName() {
        return localizedName;
    }

    public void setLocalizedName(String localizedName) {
        this.localizedName = localizedName;
    }

    public void marshallInitialization(String id, String localizedName) {
    	this.id = id;
    	this.localizedName = localizedName;
    }


    @Override
    public String toString() {
        return  localizedName;
    }

    
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof ClientDescriptorBase))
            return false;
        ClientDescriptorBase other = (ClientDescriptorBase) obj;
        if (id == null) {
            if (other.id != null)
                return false;
        } else if (!id.equals(other.id))
            return false;
        return true;
    }
}
